package com.xysl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.system.api.domain.SysDictData;
import com.ruoyi.system.api.domain.SysDictType;
import com.xysl.api.domain.XyslUser;
import com.xysl.mapper.DictDataMapper;
import com.xysl.mapper.DictTypeMapper;
import com.xysl.service.DictConfigService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DictConfigServiceImpl implements DictConfigService {


    @Resource
    private DictTypeMapper dictTypeMapper;

    @Resource
    private DictDataMapper dictDataMapper;

    /**
     * 查询字典类型数据
     * @return
     */
    @Override
    public List<SysDictType> queryDictTypeList() {
        LambdaQueryWrapper<SysDictType> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysDictType::getStatus,"0");
        return dictTypeMapper.selectList(wrapper);
    }


    /**
     * 根据字典类型获取字典选项数据
     * @param xyslUser
     * @param dictTypeCode
     * @return
     */
    @Override
    public List<SysDictData> queryDictDataByTypeList(XyslUser xyslUser, String dictTypeCode) {
        LambdaQueryWrapper<SysDictData> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysDictData::getDictType,dictTypeCode);
        wrapper.eq(SysDictData::getStatus,"0");
//        if (null != xyslUser) {
//            wrapper.eq(SysDictData::getSiteId,xyslUser.getSiteId());
//            wrapper.eq(SysDictData::getGroupId,xyslUser.getGroupId());
//            wrapper.eq(SysDictData::getGardenId,xyslUser.getGardenId());
//        }
        return dictDataMapper.selectList(wrapper);
    }
}
